package com.ruoyi.web.controller.loan.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.loan.dto.CheckMailCodeDto;
import com.ruoyi.loan.dto.UpdatePasswordDto;
import com.ruoyi.loan.dto.UserLoginDto;
import com.ruoyi.loan.dto.UserRegisterDto;
import com.ruoyi.loan.service.impl.AuthServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;

/**
 * @author coderFu
 * @create 2022/4/5
 */
@RestController
@Api(value = "authController",tags = "用户授权模块")
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    private AuthServiceImpl authService;




    @ApiOperation("用户注册")
    @PostMapping("/register")
    public AjaxResult userRegister(@RequestBody UserRegisterDto userRegisterDto){
        authService.register(userRegisterDto);
        return AjaxResult.success();
    }

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public AjaxResult userLogin(@RequestBody UserLoginDto userLoginDto){
        authService.login(userLoginDto);
        return AjaxResult.success();
    }

    @ApiOperation("校验验证码的正确性")
    @PostMapping("/checkMailCode")
    public AjaxResult checkMailCode(@RequestParam("mailCode") Integer mailCode){
        authService.checkMailCode(mailCode);
        return AjaxResult.success();
    }

    @ApiOperation("发送邮箱验证码")
    @PostMapping("/sendMailCode")
    public AjaxResult sendMailCode(@RequestParam("idCard") String idCard,@RequestParam("mail") String mail){
        authService.sendMailCode(idCard,mail);
        return AjaxResult.success();
    }

    @ApiOperation("重置密码")
    @PostMapping("/updatePassword")
    public AjaxResult updatePassword(@RequestBody UpdatePasswordDto updatePasswordDto){
        authService.updatePassword(updatePasswordDto);
        return AjaxResult.success();
    }

}
